home *** CD-ROM | disk | FTP | other *** search
- Path: news.eecs.umich.edu!usenet
- From: niranjan@eecs.umich.edu (Niranjan Ramakrishnan)
- Newsgroups: comp.lang.c
- Subject: Re: simulating fscanf for strings?
- Date: 19 Apr 1996 09:26:01 -0400
- Organization: Department of EECS, University of Michigan, Ann Arbor
- Sender: niranjan@wits-end.eecs.umich.edu
- Message-ID: <iefd9545ora.fsf@wits-end.eecs.umich.edu>
- References: <ief20llwf6c.fsf@wits-end.eecs.umich.edu>
- NNTP-Posting-Host: wits-end.eecs.umich.edu
- In-reply-to: niranjan@eecs.umich.edu's message of 18 Apr 1996 14:38:35 -0400
- X-Newsreader: Gnus v5.1
-
- >>>>> "Niranjan" == Niranjan Ramakrishnan <niranjan@eecs.umich.edu> writes:
-
- Niranjan> Hi,
- Niranjan> Does anyone know of a method to simulate what fscanf
- does (in the case of
- Niranjan> a file pointer) in a character pointer? The only closest
- thing available is
- Niranjan> sscanf but it doesn't automatically advance the pointer
-
- Hi again,
-
- I got quite a few responses for my question and I'd like to thank everybody.
- Just thought I'd mention that I think the solution to this (garnered from the
- replies) is using the "%n" option.
-
- eg
-
- char *s=(char *)malloc(sizeof(char)*20),t[10];
- int j=6,k=7,i,l,c;
- sprintf(s,"%d %d Hello",j,k);
- sscanf(s,"%d %d %n",&i,&l,&c); /* c contains number of bytes read so far */
- s+=c;
- sscanf(s,"%s",t);
- printf("i is %d, l is %d %s",i,l,t);
-
- --- prints : i is 6, l is 7 Hello ---
-
- Thanks once again,
-
- Niranjan
-
- --
- - Niranjan
-
-